<?php
	/**
	 * Dynamic Set class.
	 * @author IMP
	 */ 
	
	abstract class DynamicSet {
		private $properties = array(), $alias = array();
		
		protected final function addProperty($name, &$ref, $getter = true, $setter = true){
			$this->properties[strtolower($name)] = array('getter' => $getter, 'setter' => $setter, 'ref' => &$ref);
		}
		
		protected final function removeProperty($name){
			if(isset($this->properties[strtolower($name)])){
				unset($this->properties[strtolower($name)]);
			}
		}
		
		public final function __call($method, array $args = array()){
			$m = strtolower($method);
			
			if(substr($m, 0, 3) == 'get'){
				$prop = substr($m, 3);
				
				if(!empty($prop) && isset($this->properties[$prop]) && $this->properties[$prop]['getter']){
					return $this->properties[$prop]['ref'];
				}else{
					throw new Exception('Method ' . $method . ' cannot be found.');
				}
			}elseif(substr($m, 0, 3) == 'set'){
				$prop = substr($m, 3);
				
				if(!empty($prop) && isset($this->properties[$prop]) && $this->properties[$prop]['setter'] && count($args) >= 1){
					$this->properties[$prop]['ref'] = $args[0];
				}else{
					throw new Exception('Method ' . $method . ' cannot be found.');
				}
			}else{
				throw new Exception('Method ' . $method . ' cannot be found.');
			}
		}
	}
?>